﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Linq;
using System.Windows;
namespace WPFExcelReport
{
    public class SizeColorMatrix
    {
        public string Line { get; set; }
        public string Color { get; set; }
        public string Size { get; set; }
        public int Qty { get; set; }
    }
    public class MonthlyOrderCount
    {
        public int Year { get; set; }
        public int Month { get; set; }
        public int NumberOfOrders { get; set; }
    }
    public class YCAFSPLANData : BaseFunction
    {
        string processedfart = "";
        public SETINTEXDB INTEXDB = new SETINTEXDB();
        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        public YCAFSPLANData()
            : base()
        {
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
        }
        public YCAFSPLANData(OracleConnection _OracleDB, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_OracleDB, _proxy, userID)
        {
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
        }
        public YCAFSPLANData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
        }
        public DataSet LoadAssData()
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataRow dwData = null;
            try
            {
                dwData = INTEXDB.ICC_SECTION.NewRow();
                dwData["SDSA"] = "0247";
                SResult = INTEXDBC.QuerySDDAT(dwData, 3);
                SResult.Tables[0].TableName = "ICC_SECTION";
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    row["SDDATEN"] = Helpers.Helper.GetGB2312Value(row["SDDATEN"].ToString());
                }
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet CreateMatrix(DataTable tbABPOS)
        {
            DataSet Return = new DataSet();

            DataTable tbSC = INTEXDB.ICC_ABPOS_MAT.Clone();
            foreach (DataRow row in tbABPOS.Rows)
            {
                string krs = row["ABPAUFKRS"].ToString();
                string lfd = row["ABPAUFLFD"].ToString();
                string art = row["ABPART"].ToString();
                string color = row["ABPFARBE"].ToString();
                string size = row["ABPGROE"].ToString().Trim();
                double qty = System.Convert.ToDouble(row["ABPSOLLMENGE7"].ToString()) * 0.01;

                bool added = false;
                bool newcolor = false;
                int yc = tbSC.Columns.Count;
                int y = 0;
                added = false;
                DataRow rmx = null;
                var query = from DataRow rm in tbSC.AsEnumerable()
                            where rm["KRS"].ToString() == krs
                            && rm["LFD"].ToString() == lfd
                            && rm["ABPART"].ToString() == art
                            && rm["ABPFARBE"].ToString() == color
                            select rm;
                foreach (DataRow rm in query)
                {
                    rmx = rm;
                }
                if (rmx == null)
                {
                    rmx = tbSC.NewRow();
                    newcolor = true;
                    rmx["S"] = 0;
                    rmx["M"] = 0;
                    rmx["L"] = 0;
                    rmx["XL"] = 0;
                    rmx["SP"] = 0;
                    rmx["MP"] = 0;
                    rmx["LP"] = 0;
                    rmx["XLP"] = 0;
                }
                rmx["KRS"] = row["ABPAUFKRS"];
                rmx["LFD"] = row["ABPAUFLFD"];
                rmx["ABPSPGRD"] = row["ABPSPGRD"].ToString();
                rmx["ABPART"] = art;
                rmx["ABPFARBE"] = color;

                added = false;
                foreach (DataColumn m in tbSC.Columns)
                {
                    if (m.ColumnName == size)
                    {
                        added = true;
                        break;
                    }
                    y++;
                }
                if (!added)//未找到列；
                {
                    tbSC.Columns.Add(new DataColumn(size));
                }
                yc = tbSC.Columns.Count;
                string szQty = rmx[y].ToString();
                if (szQty.Trim() == "")
                    szQty = "0";

                double lastqty = System.Convert.ToDouble(szQty);


                rmx[y] = lastqty + qty;

                if (tbSC.Columns.Contains(size + "P"))
                {
                    double pqty = System.Convert.ToDouble(row["ABPSOLLMENGE5"].ToString()) * 0.01;
                    string szpQty = rmx[size + "P"].ToString();
                    if (szpQty.Trim() == "")
                        szpQty = "0";
                    double lastpqty = System.Convert.ToDouble(szpQty);
                    rmx[size + "P"] = lastpqty + pqty;
                }

                if (newcolor)
                {
                    tbSC.Rows.Add(rmx);
                }
            }
            double colortotal = 0;
            double total = 0;
            int ycm = tbSC.Columns.Count;
            double planQty = 0;
            foreach (DataRow row in tbSC.Rows)
            {
                colortotal = 0;
                planQty = 0;
                int y = 0;
                string sQty = row["S"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                sQty = row["M"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                sQty = row["L"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                sQty = row["XL"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                row["TQTY"] = colortotal;
                total += colortotal;

                string pQty = row["SP"].ToString();
                if (pQty.Trim() == "") pQty = "0";
                planQty += System.Convert.ToDouble(pQty);
                pQty = row["MP"].ToString();
                if (pQty.Trim() == "") pQty = "0";
                planQty += System.Convert.ToDouble(pQty);
                pQty = row["LP"].ToString();
                if (pQty.Trim() == "") pQty = "0";
                planQty += System.Convert.ToDouble(pQty);
                pQty = row["XLP"].ToString();
                if (pQty.Trim() == "") pQty = "0";
                planQty += System.Convert.ToDouble(pQty);
                row["DQTY"] = 100 * (colortotal - planQty) / planQty;
            }
            colortotal = 0;
            total = 0;
            foreach (DataRow row in tbSC.Rows)
            {
                colortotal = 0;
                int y = 0;
                string sQty = row["SP"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                sQty = row["MP"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                sQty = row["LP"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                sQty = row["XLP"].ToString();
                if (sQty.Trim() == "") sQty = "0";
                colortotal += System.Convert.ToDouble(sQty);

                row["TQTYP"] = colortotal;
                total += colortotal;
            }
            Return.Merge(tbSC);
            return Return;
        }
        public void CheckLockedQty(ref DataSet src, DataRow dwInput)
        {
            DataSet SResult = new DataSet();
            DataRow dwData = null;
            dwData = INTEXDB.ICC_ABAUFM.NewRow();
            dwData["ABAMANDANT"] = dwInput["MANDANT"];
            dwData["ABAART"] = Left(dwInput["ART"].ToString() + "            ", 20);
            dwData["ABAVAR"] = Left(dwInput["VAR"].ToString() + "            ", 3);
            dwData["ABAFARBE"] = dwInput["COLOR"];
            dwData["ABAGROE"] = "       ";
            SResult = INTEXDBC.QueryICC_ABAUFM(dwData, 5);
            foreach (DataRow rz in SResult.Tables[0].Rows)
            {
                string sptype = rz["ABAAUFTYP"].ToString();
                switch (sptype)
                {
                    case "N":
                        break;
                    case "B":
                        var query1 = from DataRow rwz in src.Tables["ICC_STOCK"].AsEnumerable()
                                     where rwz["LO"].ToString().Trim() == rz["ABAAUFKRS"].ToString().Trim()
                                     && rwz["LB"].ToString().Trim() == rz["ABAAUFLFD"].ToString().Trim()
                                     select rwz;
                        foreach (DataRow rwz in query1)
                        {
                            rwz["QTYLOCKED"] = rz["ABAQTYALLOCATE"];
                            rwz["QTYFREE"] = System.Convert.ToDouble(rwz["QTY"].ToString()) - System.Convert.ToDouble(rwz["QTYLOCKED"].ToString());
                        }
                        break;
                    case "P":
                        var query2 = from DataRow rwz in src.Tables["ICC_EKPOS"].AsEnumerable()
                                     where rwz["EKPAUFKRS"].ToString().Trim() == rz["ABAAUFKRS"].ToString().Trim()
                                     && rwz["EKPAUFLFD"].ToString().Trim() == rz["ABAAUFLFD"].ToString().Trim()
                                     && rwz["EKPAUFPOS"].ToString().Trim() == rz["ABAAUFPOS"].ToString().Trim()
                                     select rwz;
                        foreach (DataRow rwz in query2)
                        {
                            rwz["EKPQTYLOCKED"] = rz["ABAQTYRESERVE"];
                            rwz["EKPQTYFREE"] = System.Convert.ToDouble(rwz["EKPME1"].ToString()) - System.Convert.ToDouble(rwz["EKPQTYLOCKED"].ToString());
                        }
                        break;
                    default:
                        break;
                }
            }
        }
        public DataSet LoadGXDECKData(string mtype, string sections, string EKPBEKZ)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataRow dwData = null;
            try
            {
                if (sections.Trim() == "")
                {

                    MessageBox.Show("请选择区段!");
                    return SReturn;
                }
                ///读取汇总信息                
                ///
                switch (mtype)
                {
                    case "主面料":
                        dwData = INTEXDB.WDECK.NewRow();
                        dwData["WDMANDANT"] = "00";
                        dwData["WDTYP"] = "B";
                        dwData["WDART"] = Helpers.Helper.ParseSectionStr(sections);
                        SResult = INTEXDBC.QueryWDECK(dwData, 11);
                        break;
                    case "面辅料":
                        dwData = INTEXDB.WDECK.NewRow();
                        dwData["WDMANDANT"] = "00";
                        dwData["WDTYP"] = "B";
                        dwData["WDSA"] = EKPBEKZ;
                        dwData["WDART"] = Helpers.Helper.ParseSectionStr(sections);
                        SResult = INTEXDBC.QueryWDECK(dwData, 16);
                        break;
                    case "高级辅料":
                        dwData = INTEXDB.FDECK.NewRow();
                        dwData["FDMANDANT"] = "00";
                        dwData["FDTYP"] = "B";
                        dwData["FDSA"] = EKPBEKZ;
                        dwData["FDART"] = Helpers.Helper.ParseSectionStr(sections);
                        SResult = INTEXDBC.QueryFDECK(dwData, 16);
                        break;
                    case "成衣":
                        dwData = INTEXDB.FDECK.NewRow();
                        dwData["FDMANDANT"] = "00";
                        dwData["FDART"] = Helpers.Helper.ParseSectionStr(sections);
                        dwData["FDSA"] = EKPBEKZ;
                        SResult = INTEXDBC.QueryFDECK(dwData, 17);
                        break;
                }
                SResult.Tables[0].TableName = "WDECK";
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("查询完成", StatusEventType.StopProgress);
            }
            return SReturn;
        }
        public DataSet GetEKPOS(string client = "00", string wakz = "F", string art = "", string var = "", string color = "", string size = "       ", string EKPBEKZ = " ", string EKPME3 = "N")
        {
            DataSet SResult = new DataSet();
            DataSet STemp = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                #region========Purchasing order==========
                //读取采购
                if (EKPME3 == "N")
                {
                    SResult = INTEXDBC.QueryICC_EKPOS(client, wakz, art, var, color, size, EKPBEKZ, 3);
                }
                if (EKPME3 == "Y")
                {
                    SResult = INTEXDBC.QueryICC_EKPOS(client, wakz, art, var, color, size, EKPBEKZ, 5);
                }
                SReturn.Merge(SResult);
                #endregion
                #region========MakeUps==========
                DataRow dwData;
                //通常应当只有一个
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    //EKPMANDANT,EKPAUFKRS,EKPAUFLFD,EKPAUFPOS
                    dwData = INTEXDB.ICC_ABAUFM.NewRow();
                    dwData["ABAMANDANT"] = row["EKPMANDANT"];
                    dwData["ABAAUFKRS"] = row["EKPAUFKRS"];
                    dwData["ABAAUFLFD"] = row["EKPAUFLFD"];
                    dwData["ABAAUFPOS"] = row["EKPAUFPOS"];
                    STemp = INTEXDBC.QueryICC_ABAUFM(dwData, 11);
                    SReturn.Merge(STemp);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet GetEKPOS(DataRow dwInput, string EKPME3 = "N")
        {
            DataSet SResult = new DataSet();
            DataSet STemp = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                #region========Purchasing order==========
                //读取采购
                if (EKPME3 == "N")
                {
                    SResult = INTEXDBC.QueryICC_EKPOS(dwInput, 31);
                }
                if (EKPME3 == "Y")
                {
                    SResult = INTEXDBC.QueryICC_EKPOS(dwInput, 51);
                }
                if (EKPME3 == "A")
                {
                    SResult = INTEXDBC.QueryICC_EKPOS(dwInput, 32);
                }
                SReturn.Merge(SResult);
                #endregion
                #region========MakeUps==========
                DataRow dwData;
                //通常应当只有一个
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    //EKPMANDANT,EKPAUFKRS,EKPAUFLFD,EKPAUFPOS
                    dwData = INTEXDB.ICC_ABAUFM.NewRow();
                    dwData["ABAMANDANT"] = row["EKPMANDANT"];
                    dwData["ABAAUFKRS"] = row["EKPAUFKRS"];
                    dwData["ABAAUFLFD"] = row["EKPAUFLFD"];
                    dwData["ABAAUFPOS"] = row["EKPAUFPOS"];
                    STemp = INTEXDBC.QueryICC_ABAUFM(dwData, 11);
                    SReturn.Merge(STemp);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet GetDECK(SETINTEXDB src, DataRow dwInput)
        {
            DataSet SResult = new DataSet();
            DataSet STemp = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                processedfart = "";
                string art = dwInput["EKPART"].ToString();
                string tbName = dwInput.Table.TableName;
                //ICC_ABAUFM
                string krs = dwInput["EKPAUFKRS"].ToString();
                string lfd = dwInput["EKPAUFLFD"].ToString();
                string pos = dwInput["EKPAUFPOS"].ToString();
                DataRow dwData = src.ABPOS.NewRow();
                string processed = "";
                string fart = "";
                string fcolor = "";
                var qmu = from DataRow row in src.ICC_ABAUFM.AsEnumerable()
                          where row["ABAAUFKRS"].ToString() == dwInput["EKPAUFKRS"].ToString()
                          && row["ABAAUFLFD"].ToString() == dwInput["EKPAUFLFD"].ToString()
                          && row["ABAAUFPOS"].ToString() == dwInput["EKPAUFPOS"].ToString()
                          select row;
                foreach (DataRow row in qmu)
                {
                    krs = row["ABAVKAUFKRS"].ToString();
                    lfd = row["ABAVKAUFLFD"].ToString();
                    pos = row["ABAVKAUFPOS"].ToString();
                    fart = row["ABPART"].ToString();
                    fcolor = row["ABPFARBE"].ToString();
                    if (processed.Contains(krs + lfd + fart + fcolor + ";"))
                        continue;
                    processed += krs + lfd + fart + fcolor + ";";
                    dwData["ABPMANDANT"] = "00";
                    dwData["ABPAUFKRS"] = krs;
                    dwData["ABPAUFLFD"] = lfd;
                    dwData["ABPAUFPOS"] = pos;
                    dwData["ABPART"] = row["ABPART"];
                    dwData["ABPFARBE"] = row["ABPFARBE"];
                    STemp = GetABPOS(dwData);
                    SReturn.Merge(STemp);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

            DataTable tb = SReturn.Tables["FDECK"];
            if (tb != null)
            {
                foreach (DataRow X in tb.Rows)
                {
                    CheckRatio(SReturn, X, "FDECK");
                }
            }
            tb = SReturn.Tables["WDECK"];
            if (tb != null)
            {
                foreach (DataRow X in tb.Rows)
                {
                    CheckRatio(SReturn, X, "WDECK");
                }
            }
            return SReturn;
        }
        public void RepairABPOS(DataRow dwData)
        {
            DataSet SResult = new DataSet();
            DataSet Return = new DataSet();
            string pos = dwData["ABPAUFPOS"].ToString();
            SResult = INTEXDBC.QueryABPOS(dwData, 23);
            double ratio = 1;
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                if (pos != row["ABPAUFPOS"].ToString())
                {
                    ratio = Convert.ToDouble(row["ABPSOLLMENGE7"].ToString()) / Convert.ToDouble(row["ABPSOLLMENGE5"].ToString());
                    break; ;
                }
            }
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                double QTY = Math.Round(ratio * Convert.ToDouble(row["ABPSOLLMENGE5"].ToString()) * 0.01);
                row["ABPSOLLMENGE7"] = QTY * 100;
                row["ABPSOLLMENGE8"] = QTY;
                INTEXDBC.UpdateABPOS(row, 1);
            }
        }
        public DataSet GetABPOS(DataRow dwInput)
        {
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();
            DataRow dwData = null;
            try
            {
                string fart = dwInput["ABPART"].ToString();
                string fcolor = dwInput["ABPFARBE"].ToString();
                dwData = INTEXDB.ABPOS.NewRow();
                dwData["ABPMANDANT"] = dwInput["ABPMANDANT"];
                dwData["ABPAUFKRS"] = dwInput["ABPAUFKRS"];
                dwData["ABPAUFLFD"] = dwInput["ABPAUFLFD"];
                dwData["ABPART"] = dwInput["ABPART"];
                dwData["ABPFARBE"] = dwInput["ABPFARBE"];
                Result = INTEXDBC.QueryABPOS(dwData, 24);
                Return.Merge(Result);
                Result = INTEXDBC.QueryWDECK(dwData, 20);
                Return.Merge(Result);
                Result = INTEXDBC.QueryFDECK(dwData, 13);
                Return.Merge(Result);
                Result = INTEXDBC.QueryICC_ABAUFM(dwData, 30);
                Return.Merge(Result);
                if (!processedfart.Contains(fart + ";"))
                {
                    processedfart += fart + ";";
                    dwData["ABPMANDANT"] = dwInput["ABPMANDANT"];
                    dwData["ABPAUFKRS"] = dwInput["ABPAUFKRS"];
                    dwData["ABPAUFLFD"] = dwInput["ABPAUFLFD"];
                    Result = INTEXDBC.QueryFSSTUELI(dwData, 5);
                    Return.Merge(Result);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public void CheckRatio(DataSet src, DataRow dwData, string tbname)
        {
            string fart = "", fvar = "", ffarbe = "", fsize = "", mart = "", mvar = "", mfarbe = "", msize = "";
            string krs = "", lfd = "", pos = "";
            DataTable tbBOM = src.Tables["FSSTUELI"];
            DataTable tbAB = src.Tables["ABPOS"];
            double px = 1;
            if (tbBOM == null)
                return;
            if (tbAB == null)
                return;
            switch (tbname)
            {
                case "WDECK":
                    krs = dwData["WDAUFKRS"].ToString();
                    lfd = dwData["WDAUFLFD"].ToString();
                    pos = dwData["WDAUFPOS"].ToString();
                    mart = dwData["WDART"].ToString();
                    mvar = dwData["WDVAR"].ToString();
                    mfarbe = dwData["WDFARBE"].ToString();
                    msize = "       ";
                    px = 1;
                    break;
                case "FDECK":
                    krs = dwData["FDAUFKRS"].ToString();
                    lfd = dwData["FDAUFLFD"].ToString();
                    pos = dwData["FDAUFPOS"].ToString();
                    mart = dwData["FDART"].ToString();
                    mvar = dwData["FDVAR"].ToString();
                    mfarbe = dwData["FDFARBE"].ToString();
                    msize = dwData["FDGROE"].ToString();
                    px = 0.01;
                    break;
            }
            var qAB = from DataRow row in tbAB.AsEnumerable()
                      where row["ABPAUFKRS"].ToString() == krs
                      && row["ABPAUFLFD"].ToString() == lfd
                      && row["ABPAUFPOS"].ToString() == pos
                      select row;
            foreach (DataRow dwABPOS_EXT in qAB)
            {
                fart = dwABPOS_EXT["ABPART"].ToString();
                fvar = dwABPOS_EXT["ABPVAR"].ToString();
                ffarbe = dwABPOS_EXT["ABPFARBE"].ToString();
                fsize = dwABPOS_EXT["ABPGROE"].ToString();
                var qbom = from DataRow dwBOM in tbBOM.AsEnumerable()
                           where dwBOM["FSSMART"].ToString().Trim() == mart.Trim()
                           && dwBOM["FSSMVAR"].ToString().Trim() == mvar.Trim()
                           && dwBOM["FSSMFARBE"].ToString().Trim() == mfarbe.Trim()
                           && dwBOM["FSSMGROE"].ToString().Trim() == msize.Trim()
                           && dwBOM["FSSART"].ToString().Trim() == fart.Trim()
                           select dwBOM;
                foreach (DataRow dwBOM in qbom)
                {
                    string FSSVAR = dwBOM["FSSVAR"].ToString();
                    string FSSFARBE = dwBOM["FSSFARBE"].ToString().Trim();
                    string FSSGROE = dwBOM["FSSGROE"].ToString();
                    string FSSAUFM = dwBOM["FSSAUFM"].ToString();
                    string FSSVERP = dwBOM["FSSVERP"].ToString();
                    string FSSPOSTYP = dwBOM["FSSPOSTYP"].ToString();

                    //============ 
                    string FSSPOS = dwBOM["FSSPOS"].ToString();
                    string FSSMATKZ = dwBOM["FSSMATKZ"].ToString();
                    string FSSMART = dwBOM["FSSMART"].ToString();
                    string FSSMVAR = dwBOM["FSSMVAR"].ToString();
                    string FSSMFARBE = dwBOM["FSSMFARBE"].ToString();
                    string FSSMGROE = dwBOM["FSSMGROE"].ToString();
                    string FSSVERBR = dwBOM["FSSVERBR"].ToString();
                    string FSSVBME = dwBOM["FSSVBME"].ToString();
                    string FSSVBFKT = dwBOM["FSSVBFKT"].ToString();
                    string FSSVERL = dwBOM["FSSVERL"].ToString();
                    string ratio = "1";
                    ratio = (Convert.ToDouble(FSSVERBR) * 0.001 * px * Convert.ToDouble(FSSVBFKT) * 0.000001 * (1 + Convert.ToDouble(FSSVERL) * 0.0001)).ToString();

                    //先处理颜色                  

                    if (FSSFARBE.Trim() == "*")
                    {
                        FSSMFARBE = ffarbe;
                    }

                    if (FSSFARBE.Trim() != "")
                    {
                        if (FSSFARBE.Trim() != "*")
                        {
                            if (FSSFARBE.Trim() != ffarbe.Trim())
                                continue;
                        }
                    }
                    if (FSSGROE.Trim() != "")
                    {
                        if (FSSGROE.Trim() != "*")
                        {
                            if (FSSGROE.Trim() != fsize.Trim())
                                continue;
                        }
                    }
                    dwData["RATIO"] = ratio;
                }
            }
        }
        public DataSet ResetData(SETINTEXDB src, DataRow dwEKPOS)
        {
            DataSet SResult = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                SResult = CreateMatrix(src.ABPOS);
                SReturn.Merge(SResult);
                SReturn.Merge(ResetGAAUF(src));
                RefreshICC_ABAUFM(src, "GAAUF");
                SReturn.Merge(ResetMDECK(src));
                RefreshICC_ABAUFM(src, "MDECK");
                SReturn.Merge(ResetWDECK(src, dwEKPOS));
                RefreshICC_ABAUFM(src, "WDECK");
                SReturn.Merge(ResetFDECK(src));
                RefreshICC_ABAUFM(src, "FDECK");
                SReturn.Merge(ResetABFOLGE(src));
                SReturn.Merge(ResetABPR(src));
                SReturn.Merge(ResetICC_ABPOSFS(src));

                SReturn.Merge(ResetABAUFM(src));
                SReturn.Merge(src.ABPOS);
                SReturn.Merge(src.WDECK);
                SReturn.Merge(src.MDECK);
                SReturn.Merge(src.FDECK);
                SReturn.Merge(src.GAAUF);
                SReturn.Merge(src.ICC_ABAUFM);
                SReturn.Merge(src.ICC_EKPOS);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet ResetABAUFM(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                /*ABASGESLG ABARSTSLG ABPSOLLMENGE7	10 ABAAENDBEN ABAAENDDAT*/
                foreach (DataRow row in src.ABPOS.Rows)
                {
                    string client = row["ABPMANDANT"].ToString();
                    string krs = row["ABPAUFKRS"].ToString();
                    string lfd = row["ABPAUFLFD"].ToString();
                    string pos = row["ABPAUFPOS"].ToString();
                    string user = row["ABPAENDBEN"].ToString();
                    string date = row["ABPAENDDAT"].ToString();
                    decimal qty = System.Convert.ToDecimal(row["ABPSOLLMENGE7"].ToString());
                    var query = from rx in src.ABAUFM.AsEnumerable()
                                where rx["ABAAUFKFRS"].ToString() == krs
                                && rx["ABAAUFKLFD"].ToString() == lfd
                                && rx["ABAAUFKPOS"].ToString() == pos
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        rx["ABASGESLG"] = System.Math.Round(qty * 10, 0);
                        rx["ABARSTSLG"] = System.Math.Round(qty * 10, 0);
                        rx["ABAAENDBEN"] = user;
                        rx["ABAAENDDAT"] = date;
                    }
                }
                SReturn.Merge(src.ABAUFM);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet UpdateICC_ABAUFM(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();

            /*ABASGESLG ABARSTSLG ABPSOLLMENGE7	10 ABAAENDBEN ABAAENDDAT*/
            foreach (DataRow row in src.ICC_ABAUFM.Rows)
            {
                string client = "00", krs = "", lfd = "", pos = "";
                krs = row["ABAVKAUFKRS"].ToString();
                lfd = row["ABAVKAUFLFD"].ToString();
                pos = row["ABAVKAUFPOS"].ToString();
                double qty = System.Convert.ToDouble(row["ABARESMG"].ToString());
                if (qty == 0)
                {
                    //INTEXDBC.DeleteICC_ABAUFM(client, krs, lfd, pos, null, 1);
                    throw new Exception("出现异常，请立即联系管理员。");
                }
                else
                {
                    INTEXDBC.UpdateICC_ABAUFM(row, 3);
                }
            }
            SReturn.Merge(src.ABAUFM);

            return SReturn;
        }
        public DataSet ResetABPR(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                /*ARAENDBEN ARAENDDAT*/
                foreach (DataRow row in src.ABPOS.Rows)
                {
                    string client = row["ABPMANDANT"].ToString();
                    string krs = row["ABPAUFKRS"].ToString();
                    string lfd = row["ABPAUFLFD"].ToString();
                    string pos = row["ABPAUFPOS"].ToString();
                    string user = row["ABPAENDBEN"].ToString();
                    string date = row["ABPAENDDAT"].ToString();
                    var query = from rx in src.ABPR.AsEnumerable()
                                where rx["ABAAUFKFRS"].ToString() == krs
                                && rx["ABAAUFKLFD"].ToString() == lfd
                                && rx["ABAAUFKPOS"].ToString() == pos
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        rx["ARAENDBEN"] = user;
                        rx["ARAENDDAT"] = date;
                    }
                }
                SReturn.Merge(src.ABPR);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet ResetICC_ABPOSFS(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                /*ARAENDBEN ARAENDDAT*/
                foreach (DataRow row in src.ABPOS.Rows)
                {
                    string krs = row["ABPAUFKRS"].ToString();
                    string lfd = row["ABPAUFLFD"].ToString();
                    string farbe = row["ABPFARBE"].ToString();
                    string size = row["ABPGROE"].ToString().Trim();
                    string qty = row["ABPSOLLMENGE7"].ToString().Trim();
                    var query = from rx in src.ICC_ABPOSFS.AsEnumerable()
                                where rx["KRS"].ToString() == krs
                                && rx["LFD"].ToString() == lfd
                                && rx["FARBE"].ToString() == farbe
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        rx[size] = qty;
                    }
                }
                SReturn.Merge(src.ABPR);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet ResetABFOLGE(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                /*ABFSOLLSTK 0.01 ABFSOLLMG 10*/
                foreach (DataRow row in src.ABPOS.Rows)
                {
                    string client = row["ABPMANDANT"].ToString();
                    string krs = row["ABPAUFKRS"].ToString();
                    string lfd = row["ABPAUFLFD"].ToString();
                    string pos = row["ABPAUFPOS"].ToString();
                    string user = row["ABPAENDBEN"].ToString();
                    string date = row["ABPAENDDAT"].ToString();
                    decimal qty = System.Convert.ToDecimal(row["ABPSOLLMENGE7"].ToString());
                    var query = from rx in src.ABFOLGE.AsEnumerable()
                                where rx["ABFAUFKRS"].ToString() == krs
                                && rx["ABFAUFLFD"].ToString() == lfd
                                && rx["ABFAUFPOS"].ToString() == pos
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        rx["ABFSOLLSTK"] = System.Math.Round(qty * System.Convert.ToDecimal(0.01), 0);
                        rx["ABFSOLLMG"] = System.Math.Round(qty * 10, 0);
                        rx["ABFAENDBEN"] = user;
                        rx["ABFAENDDAT"] = date;
                    }
                }
                SReturn.Merge(src.ABAUFM);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet ResetGAAUF(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            double colortotal = 0;
            double total = 0;
            int yc = 0;
            try
            {
                DataRow dwABPOS = null;

                DataTable tbYarn = INTEXDB.ICC_GAAUFMAT.Clone();
                tbYarn.TableName = "ICC_GAAUFMAT";
                foreach (DataRow row in src.GAAUF.Rows)
                {
                    DataRow rt = null;
                    bool newrow = false;
                    decimal lastqty = 0;

                    dwABPOS = null;
                    var query = from DataRow rx in src.ABPOS.AsEnumerable()
                                where row["ABPAUFKRS"].ToString() == row["GAAUFKRS"].ToString()
                                && row["ABPAUFLFD"].ToString() == row["GAAUFLFD"].ToString()
                                && row["ABPAUFPOS"].ToString() == row["GAAUFPOS"].ToString()
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        dwABPOS = rx;
                    }
                    if (dwABPOS == null)
                        continue;
                    decimal ratio = 0;
                    decimal qty = System.Convert.ToDecimal(dwABPOS["ABPSOLLMENGE7"].ToString());
                    if (qty == 0)
                        continue;
                    decimal mqty = System.Convert.ToDecimal(row["GAKG1"].ToString());
                    string rate = row["RATIO"].ToString();
                    if (rate.Trim() == "")
                    {
                        rate = (System.Math.Round(mqty / qty, 3)).ToString();
                        row["RATIO"] = rate;
                    }
                    ratio = System.Convert.ToDecimal(rate);
                    mqty = qty * ratio;
                    row["GAKG1"] = mqty;

                    string mart = row["GAART"].ToString();
                    string mvar = row["GAVAR"].ToString();
                    string mcolor = row["GAFARBE"].ToString();
                    string mum = "KG";
                    var qg = from DataRow rowt in tbYarn.AsEnumerable()
                             where rowt["ART"].ToString() == mart
                             && rowt["VAR"].ToString() == mvar
                             && rowt["FARBE"].ToString() == mcolor
                             select rowt;
                    foreach (DataRow rowt in qg)
                    {
                        rt = rowt;
                        if (rowt["TQTY"].ToString().Trim() == "")
                        {
                            rowt["TQTY"] = "0";
                        }
                        lastqty = System.Convert.ToDecimal(rowt["TQTY"].ToString());
                    }
                    if (rt == null)
                    {
                        newrow = true;
                        rt = tbYarn.NewRow();
                    }
                    rt["ART"] = mart;
                    rt["VAR"] = mvar;
                    rt["FARBE"] = mcolor;
                    rt["UM"] = mum;
                    rt["TQTY"] = lastqty + mqty;
                    if (newrow)
                    {
                        tbYarn.Rows.Add(rt);
                    }
                }

                SReturn.Merge(tbYarn);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet ResetWDECK(SETINTEXDB src, DataRow dwInput)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            double colortotal = 0;
            double total = 0;
            int yc = 0;
            try
            {

                DataRow dwABPOS = null;
                DataTable tbFabric = INTEXDB.ICC_WDECKMAT.Clone();
                tbFabric.TableName = "ICC_WDECKMAT";
                foreach (DataRow rwd in src.WDECK.Rows)
                {
                    DataRow rt = null;
                    bool newrow = false;
                    decimal lastqty = 0;
                    dwABPOS = null;
                    var query = from DataRow rx in src.ABPOS.AsEnumerable()
                                where rx["ABPAUFKRS"].ToString() == rwd["WDAUFKRS"].ToString()
                                && rx["ABPAUFLFD"].ToString() == rwd["WDAUFLFD"].ToString()
                                && rx["ABPAUFPOS"].ToString() == rwd["WDAUFPOS"].ToString()
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        dwABPOS = rx;
                    }
                    if (dwABPOS == null)
                        continue;
                    decimal ratio = 0;
                    decimal qty = System.Convert.ToDecimal(dwABPOS["ABPSOLLMENGE7"].ToString());
                    if (qty == 0)
                        continue;
                    decimal mqty = System.Convert.ToDecimal(rwd["WDBEDARF"].ToString());
                    string mum = rwd["UM"].ToString().Trim();
                    string rlfd = rwd["FGRLFD"].ToString().Trim();

                    string rate = rwd["RATIO"].ToString();
                    ratio = System.Convert.ToDecimal(rate);
                    mqty = qty * ratio;//用最新的数量进行比例计算
                    rwd["WDBEDARF"] = System.Math.Floor(mqty / 10) * 10;//根据成衣件数，获得需求的面料数量

                    string mart = rwd["WDART"].ToString();
                    string mvar = rwd["WDVAR"].ToString();
                    string mcolor = rwd["WDFARBE"].ToString();

                    var qg = from DataRow rowt in tbFabric.AsEnumerable()
                             where rowt["ART"].ToString() == mart
                             && rowt["VAR"].ToString() == mvar
                             && rowt["FARBE"].ToString() == mcolor
                             select rowt;

                    foreach (DataRow rowt in qg)
                    {
                        rt = rowt;
                        if (rowt["TQTY"].ToString().Trim() == "")
                        {
                            rowt["TQTY"] = "0";
                        }
                        lastqty = System.Convert.ToDecimal(rowt["TQTY"].ToString());
                    }
                    if (rt == null)
                    {
                        newrow = true;
                        rt = tbFabric.NewRow();
                    }
                    rt["ART"] = mart;
                    rt["VAR"] = mvar;
                    rt["FARBE"] = mcolor;
                    rt["UM"] = mum;
                    rt["FGRLFD"] = rwd["FGRLFD"];
                    rt["TQTY"] = lastqty + mqty;
                    rt["STQTY"] = rt["TQTY"];
                    if (mum.Trim() == "KG")
                    {
                        rt["STQTY"] = (lastqty + mqty) * System.Convert.ToDecimal(rlfd) / 1000;
                    }
                    if (newrow)
                    {
                        tbFabric.Rows.Add(rt);
                    }
                }
                SReturn.Merge(tbFabric);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public void RefreshICC_ABAUFM(SETINTEXDB src, string tbName)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            string krs = "", lfd = "", pos = "", upos = "", qty = "0";
            string mart = "", mvar = "", mfarbe = "", msize = "";
            double px = 1;
            string processeddeck = "";
            DataTable table = src.Tables[tbName];
            string RATIO = "1";
            foreach (DataRow dwData in table.Rows)
            {
                switch (tbName)
                {
                    case "WDECK":
                        krs = dwData["WDAUFKRS"].ToString();
                        lfd = dwData["WDAUFLFD"].ToString();
                        pos = dwData["WDAUFPOS"].ToString();
                        upos = dwData["WDUPOS"].ToString();
                        qty = dwData["WDBEDARF"].ToString();
                        mart = dwData["WDART"].ToString();
                        mvar = dwData["WDVAR"].ToString();
                        mfarbe = dwData["WDFARBE"].ToString();
                        RATIO = dwData["RATIO"].ToString();
                        msize = "       ";
                        break;
                    case "FDECK":
                        krs = dwData["FDAUFKRS"].ToString();
                        lfd = dwData["FDAUFLFD"].ToString();
                        pos = dwData["FDAUFPOS"].ToString();
                        qty = dwData["FDMENGE"].ToString();
                        mart = dwData["FDART"].ToString();
                        mvar = dwData["FDVAR"].ToString();
                        mfarbe = dwData["FDFARBE"].ToString();
                        msize = dwData["FDGROE"].ToString();
                        RATIO = dwData["RATIO"].ToString();
                        px = 100;
                        break;
                    case "MDECK":
                        krs = dwData["MDAUFKRS"].ToString();
                        lfd = dwData["MDAUFLFD"].ToString();
                        pos = dwData["MDAUFPOS"].ToString();
                        upos = dwData["MDFPOS"].ToString();
                        qty = dwData["MDMENGE"].ToString();
                        mart = dwData["MDMAT"].ToString();
                        mvar = dwData["MDVAR"].ToString();
                        RATIO = dwData["RATIO"].ToString();
                        mfarbe = "          ";
                        msize = "       ";
                        px = 100;
                        break;
                }
                var query = from DataRow row in src.ICC_ABAUFM.AsEnumerable()
                            where row["ABAVKAUFKRS"].ToString() == krs
                            && row["ABAVKAUFLFD"].ToString() == lfd
                            && row["ABAVKAUFPOS"].ToString() == pos
                            && row["ABAART"].ToString().Trim() == mart.Trim()
                            && row["ABAVAR"].ToString().Trim() == mvar.Trim()
                            && row["ABAFARBE"].ToString().Trim() == mfarbe.Trim()
                            && row["ABAGROE"].ToString().Trim() == msize.Trim()
                            select row;
                foreach (DataRow row in query)
                {
                    row["RATIO"] = RATIO;
                    row["ABARESMG"] = System.Convert.ToDouble(qty) * 0.01 * px;
                }
            }
        }
        public DataSet ResetFDECK(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            double colortotal = 0;
            double total = 0;
            int yc = 0;
            try
            {
                DataRow dwABPOS = null;
                DataTable tbFMat = INTEXDB.ICC_FDECKMAT.Clone();
                tbFMat.TableName = "ICC_FDECKMAT";
                foreach (DataRow row in src.FDECK.Rows)
                {
                    if (row["FDTYP"].ToString() == "Z")
                    {
                        continue;
                    }
                    DataRow rt = null;
                    bool newrow = false;
                    decimal lastqty = 0;
                    dwABPOS = null;
                    var query = from DataRow rx in src.ABPOS.AsEnumerable()
                                where rx["ABPAUFKRS"].ToString() == row["FDAUFKRS"].ToString()
                                && rx["ABPAUFLFD"].ToString() == row["FDAUFLFD"].ToString()
                                && rx["ABPAUFPOS"].ToString() == row["FDAUFPOS"].ToString()
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        dwABPOS = rx;
                    }
                    if (dwABPOS == null)
                        continue;
                    decimal ratio = 0;
                    decimal qty = System.Convert.ToDecimal(dwABPOS["ABPSOLLMENGE7"].ToString());
                    if (qty == 0)
                        continue;
                    decimal mqty = System.Convert.ToDecimal(row["FDMENGE"].ToString());
                    string rate = row["RATIO"].ToString();
                    ratio = System.Convert.ToDecimal(rate);
                    mqty = qty * ratio;
                    row["FDMENGE"] = mqty;
                    string mart = row["FDART"].ToString();
                    string mvar = row["FDVAR"].ToString();
                    string mcolor = row["FDFARBE"].ToString();
                    string msize = row["FDGROE"].ToString();
                    string mum = "PCS";
                    if (!tbFMat.Columns.Contains(msize))
                    {
                        tbFMat.Columns.Add(msize, typeof(System.Decimal));
                    }
                    var qg = from DataRow rowt in tbFMat.AsEnumerable()
                             where rowt["ART"].ToString() == mart
                             && rowt["VAR"].ToString() == mvar
                             && rowt["FARBE"].ToString() == mcolor
                             && rowt["SIZE"].ToString() == msize
                             select rowt;
                    foreach (DataRow rowt in qg)
                    {
                        rt = rowt;
                        if (rowt["TQTY"].ToString().Trim() == "")
                        {
                            rowt["TQTY"] = "0";
                        }
                        lastqty = System.Convert.ToDecimal(rowt["TQTY"].ToString());
                    }
                    if (rt == null)
                    {
                        newrow = true;
                        rt = tbFMat.NewRow();
                    }
                    rt["ART"] = mart;
                    rt["VAR"] = mvar;
                    rt["FARBE"] = mcolor;
                    rt["SIZE"] = msize;
                    rt["UM"] = mum;
                    rt["TQTY"] = lastqty + mqty;
                    if (newrow)
                    {
                        tbFMat.Rows.Add(rt);
                    }
                }
                SReturn.Merge(tbFMat);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet ResetMDECK(SETINTEXDB src)
        {
            DataSet Result = new DataSet();
            DataSet SReturn = new DataSet();
            double colortotal = 0;
            double total = 0;
            int yc = 0;
            try
            {
                DataRow dwABPOS = null;
                DataTable tbMat = INTEXDB.ICC_MDECKMAT.Clone();
                tbMat.TableName = "ICC_MDECKMAT";
                foreach (DataRow row in src.MDECK.Rows)
                {
                    DataRow rt = null;
                    bool newrow = false;
                    decimal lastqty = 0;
                    dwABPOS = null;
                    var query = from DataRow rx in src.ABPOS.AsEnumerable()
                                where rx["ABPAUFKRS"].ToString() == row["MDAUFKRS"].ToString()
                                && rx["ABPAUFLFD"].ToString() == row["MDAUFLFD"].ToString()
                                && rx["ABPAUFPOS"].ToString() == row["MDAUFPOS"].ToString()
                                select rx;
                    foreach (DataRow rx in query)
                    {
                        dwABPOS = rx;
                    }
                    if (dwABPOS == null)
                        continue;
                    decimal ratio = 0;
                    decimal qty = System.Convert.ToDecimal(dwABPOS["ABPSOLLMENGE7"].ToString());
                    if (qty == 0)
                        continue;
                    decimal mqty = System.Convert.ToDecimal(row["MDMENGE"].ToString());
                    string rate = row["RATIO"].ToString();
                    if (rate.Trim() == "")
                    {
                        rate = (System.Math.Round(mqty / qty, 3)).ToString();
                        row["RATIO"] = rate;
                    }
                    ratio = System.Convert.ToDecimal(ratio);
                    mqty = qty * ratio;
                    row["MDMENGE"] = mqty;

                    string mart = row["MDMAT"].ToString();
                    string mvar = row["MDVAR"].ToString();
                    string mum = "PCS";
                    var qg = from DataRow rowt in tbMat.AsEnumerable()
                             where rowt["ART"].ToString() == mart
                             && rowt["VAR"].ToString() == mvar
                             select rowt;

                    foreach (DataRow rowt in qg)
                    {
                        rt = rowt;
                        if (rowt["TQTY"].ToString().Trim() == "")
                        {
                            rowt["TQTY"] = "0";
                        }
                        lastqty = System.Convert.ToDecimal(rowt["TQTY"].ToString());
                    }
                    if (rt == null)
                    {
                        newrow = true;
                        rt = tbMat.NewRow();
                    }
                    rt["ART"] = mart;
                    rt["VAR"] = mvar;
                    rt["UM"] = mum;
                    rt["TQTY"] = lastqty + mqty;
                    if (newrow)
                    {
                        tbMat.Rows.Add(rt);
                    }
                }
                SReturn.Merge(tbMat);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public string Save2Intex(SETINTEXDB src)
        {
            string text = "";
            bool zeroqty = false;
            try
            {
                var query = from DataRow rx in src.ABPOS.AsEnumerable()
                            where System.Convert.ToDecimal(rx["ABPSOLLMENGE7"].ToString()) == 0
                            select rx;
                foreach (DataRow rx in query)
                {
                    zeroqty = true;
                    text += rx["ABPFARBE"].ToString() + ",";

                }
                if (zeroqty)
                {
                    MessageBox.Show("分配数量为0" + text + "。请删除生产需求!");
                    return text;
                }
                foreach (DataRow row in src.ABPOS.Rows)
                {
                    string client = row["ABPMANDANT"].ToString();
                    string krs = row["ABPAUFKRS"].ToString();
                    string lfd = row["ABPAUFLFD"].ToString();
                    string pos = row["ABPAUFPOS"].ToString();
                    decimal qty = System.Convert.ToDecimal(row["ABPSOLLMENGE7"].ToString());
                    /*if (qty == 0)
                    {
                        INTEXDBC.DeleteABFOLGE(client, krs, lfd, pos);
                        INTEXDBC.DeleteGAAUF(client, krs, lfd, pos);
                        INTEXDBC.DeleteMDECK(client, krs, lfd, pos);
                        INTEXDBC.DeleteWDECK(client, krs, lfd, pos);
                        INTEXDBC.DeleteFDECK(client, krs, lfd, pos);
                        INTEXDBC.DeleteABPOS(client, krs, lfd, pos);
                        INTEXDBC.DeleteABPR(client, krs, lfd, pos);
                        continue;
                    }*/
                    row["ABPSOLLMENGE8"] = System.Math.Round(qty / 100, 0);
                    INTEXDBC.UpdateABPOS(row, 2);
                    string processed = text;
                    text = row["ABPART"].ToString().Trim() + "-" + row["ABPFARBE"].ToString().Trim() + "已保存";
                    if (processed.Contains(text))
                        continue;
                    text += processed;
                }
                UpdateICC_ABAUFM(src);

                foreach (DataRow row in src.WDECK.Rows)
                {
                    INTEXDBC.UpdateWDECK(row);
                }
                foreach (DataRow row in src.FDECK.Rows)
                {
                    INTEXDBC.UpdateFDECK(row);
                }
                foreach (DataRow row in src.MDECK.Rows)
                {
                    INTEXDBC.UpdateMDECK(row);
                }
                foreach (DataRow row in src.GAAUF.Rows)
                {
                    INTEXDBC.UpdateGAAUF(row);
                }
                foreach (DataRow row in src.ABPR.Rows)
                {
                    INTEXDBC.UpdateABPR(row);
                }
                foreach (DataRow row in src.ABAUFM.Rows)
                {
                    INTEXDBC.UpdateABAUFM(row);
                }
                foreach (DataRow row in src.ABFOLGE.Rows)
                {
                    INTEXDBC.UpdateABFOLGE(row);
                }
                foreach (DataRow row in src.ICC_ABPOSFS.Rows)
                {
                    INTEXDBC.UpdateICC_ABPOSFS(row, 1);
                }
                foreach (DataRow row in src.ICC_ABPOS_MAT.Rows)
                {
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 31);
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 32);
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 33);
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 34);
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 35);
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 36);
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 37);
                    INTEXDBC.UpdateICC_ABPOS_MAT(row, 38);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                text = "保存有不成功！";
            }
            return text;
        }
        public override DataSet LogIn(string MANDANT, string UsingID, System.Security.SecureString sPassword)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult;
            DataTable tableLocal = null;
            OracleCommand or1;
            try
            {
                IntPtr p = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(sPassword);
                string Password = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p);
                UsingID = UsingID.Trim().ToUpper();
                Password = Password.Trim().ToUpper();
                DataRow dwTemp = INTEXDB.HRSTAMM.NewRow();
                dwTemp["HRMANDANT"] = MANDANT;
                dwTemp["HRBENID"] = Left(UsingID + "                    ", 8);
                dwTemp["HRDFAX"] = Left(Password + "                    ", 20);
                SResult = INTEXDBC.QueryHRSTAMM(dwTemp, 1);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); ;
            }
            return SReturn;
        }
    }
}
